namespace CodeCamp.EFDAL.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class AddEmailInitial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.cc_EmailCampaigns",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        EventId = c.Int(nullable: false),
                        CampaignStatusId = c.Int(nullable: false),
                        RecipientTypeId = c.Int(nullable: false),
                        EmailView = c.String(nullable: false, maxLength: 256),
                        Subject = c.String(nullable: false, maxLength: 192),
                        ReplyToAddress = c.String(maxLength: 192),
                        Description = c.String(nullable: false, maxLength: 512),
                        Salutation = c.String(nullable: false, maxLength: 256),
                        CreatedUTC = c.DateTime(nullable: false),
                        CreatedBy = c.String(nullable: false, maxLength: 128),
                        UpdatedUTC = c.DateTime(),
                        UpdatedBy = c.String(maxLength: 128),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.cc_Events", t => t.EventId)
                .Index(t => t.EventId);
            
            CreateTable(
                "dbo.cc_EmailItems",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        EventId = c.Int(nullable: false),
                        SendStatusId = c.Int(nullable: false),
                        TestMessage = c.Boolean(nullable: false),
                        EmailCampaignId = c.Int(),
                        EmailView = c.String(nullable: false, maxLength: 256),
                        SiteUserId = c.Int(),
                        PresenterId = c.Int(),
                        EmailTo = c.String(nullable: false, maxLength: 192),
                        FirstName = c.String(nullable: false, maxLength: 128),
                        LastName = c.String(maxLength: 128),
                        Subject = c.String(nullable: false, maxLength: 192),
                        ReplyToAddress = c.String(maxLength: 192),
                        Salutation = c.String(nullable: false, maxLength: 256),
                        CreatedUTC = c.DateTime(nullable: false),
                        CreatedBy = c.String(nullable: false, maxLength: 128),
                        SentUTC = c.DateTime(),
                        SentBy = c.String(maxLength: 256),
                        CustomContent1 = c.String(maxLength: 1024),
                        CustomContent2 = c.String(maxLength: 1024),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.cc_Events", t => t.EventId)
                .ForeignKey("dbo.cc_EmailCampaigns", t => t.EmailCampaignId)
                .ForeignKey("dbo.cc_SiteUsers", t => t.SiteUserId)
                .ForeignKey("dbo.cc_Presenters", t => t.PresenterId)
                .Index(t => t.EventId)
                .Index(t => t.EmailCampaignId)
                .Index(t => t.SiteUserId)
                .Index(t => t.PresenterId);
            
            AddColumn("dbo.cc_SiteUsers", "NewEventEmailOptOut", c => c.Boolean(nullable: false));
        }
        
        public override void Down()
        {
            DropIndex("dbo.cc_EmailItems", new[] { "PresenterId" });
            DropIndex("dbo.cc_EmailItems", new[] { "SiteUserId" });
            DropIndex("dbo.cc_EmailItems", new[] { "EmailCampaignId" });
            DropIndex("dbo.cc_EmailItems", new[] { "EventId" });
            DropIndex("dbo.cc_EmailCampaigns", new[] { "EventId" });
            DropForeignKey("dbo.cc_EmailItems", "PresenterId", "dbo.cc_Presenters");
            DropForeignKey("dbo.cc_EmailItems", "SiteUserId", "dbo.cc_SiteUsers");
            DropForeignKey("dbo.cc_EmailItems", "EmailCampaignId", "dbo.cc_EmailCampaigns");
            DropForeignKey("dbo.cc_EmailItems", "EventId", "dbo.cc_Events");
            DropForeignKey("dbo.cc_EmailCampaigns", "EventId", "dbo.cc_Events");
            DropColumn("dbo.cc_SiteUsers", "NewEventEmailOptOut");
            DropTable("dbo.cc_EmailItems");
            DropTable("dbo.cc_EmailCampaigns");
        }
    }
}
